package com.mt.utils;

import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * @author Wang
 * @Description 使用一个统一的线程池管理
 * @date 2020/11/29-12:08
 */

@Component
public class ThreadPoolUtils {
    // ThreadPoolExecutor pool =new ThreadPoolExecutor();
    private static volatile ThreadPoolExecutor pool;
    static int  MAX_THREAD_COUNT;
    static int CORE_THREAD_COUNT;
    private static BlockingQueue<Runnable> taskQueue=new LinkedBlockingQueue<>();

    public static void getInstance() {
        if (pool == null) {
            synchronized (ThreadPoolUtils.class) {
                if (pool==null){
                    pool=new ThreadPoolExecutor(MAX_THREAD_COUNT,CORE_THREAD_COUNT,3000L,
                            TimeUnit.MILLISECONDS,taskQueue);
                }
            }
            }
        }
    }
